<template>
  <main-layout>
    <main class="main">
      <!-- 轮播图 -->
      <div class="banner-section">
        <carousel-component />
      </div>

      <!-- 服务特点 -->
      <div class="features">
        <div class="container">
          <div class="feature-item">
            <i class="fas fa-truck"></i>
            <span>全城配送</span>
          </div>
          <div class="feature-item">
            <i class="fas fa-clock"></i>
            <span>准时送达</span>
          </div>
          <div class="feature-item">
            <i class="fas fa-shield-alt"></i>
            <span>品质保证</span>
          </div>
          <div class="feature-item">
            <i class="fas fa-redo"></i>
            <span>七天退换</span>
          </div>
        </div>
      </div>

      <!-- 热门商品 -->
      <section class="featured-products">
        <div class="container">
          <div class="section-header">
            <h2>热门鲜花</h2>
            <router-link to="/products" class="view-all"
              >查看全部 <i class="fas fa-angle-right"></i
            ></router-link>
          </div>
          <div class="product-grid">
            <product-card
              v-for="flower in $store.state.flowers"
              :key="flower.id"
              :product="flower"
            />
          </div>
        </div>
      </section>

      <!-- 新品上市 -->
      <section class="new-arrivals">
        <div class="container">
          <div class="section-header">
            <h2>新品上市</h2>
            <router-link to="/products?type=new" class="view-all"
              >查看全部 <i class="fas fa-angle-right"></i
            ></router-link>
          </div>
          <div class="product-grid">
            <product-card
              v-for="flower in newArrivals"
              :key="flower.id"
              :product="flower"
            />
          </div>
        </div>
      </section>

      <!-- 品牌优势 -->
      <section class="advantages">
        <div class="container">
          <div class="section-header">
            <h2>品牌优势</h2>
          </div>
          <div class="advantages-grid">
            <div class="advantage-item">
              <div class="advantage-icon">
                <i class="fas fa-award"></i>
              </div>
              <h3>优质花材</h3>
              <p>严选优质花材，确保每一束花都新鲜美丽</p>
            </div>
            <div class="advantage-item">
              <div class="advantage-icon">
                <i class="fas fa-truck-loading"></i>
              </div>
              <h3>专业配送</h3>
              <p>专业花艺师打包，专业物流配送，保证完美送达</p>
            </div>
            <div class="advantage-item">
              <div class="advantage-icon">
                <i class="fas fa-hand-holding-heart"></i>
              </div>
              <h3>贴心服务</h3>
              <p>专业客服团队，为您提供贴心的购物体验</p>
            </div>
            <div class="advantage-item">
              <div class="advantage-icon">
                <i class="fas fa-shield-alt"></i>
              </div>
              <h3>品质保证</h3>
              <p>支持七天无理由退换，让您购物无忧</p>
            </div>
          </div>
        </div>
      </section>
    </main>
  </main-layout>
</template>

<script>
import MainLayout from "@/components/layouts/MainLayout.vue";
import CarouselComponent from "@/components/CarouselComponent.vue";
import ProductCard from "@/components/ProductCard.vue";

export default {
  name: "HomeView",
  components: {
    MainLayout,
    CarouselComponent,
    ProductCard,
  },
  data() {
    return {
      newArrivals: [],
    };
  },
  mounted() {
    this.$store.dispatch("fetchFlowers");
    // 模拟获取新品数据
    this.newArrivals = this.$store.state.flowers.slice(0, 4);
  },
};
</script>

<style scoped>
.main {
  min-height: calc(100vh - 200px);
}

.features {
  padding: 40px 0;
  background: #f8f9fa;
  margin-bottom: 40px;
}

.features .container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 30px;
}

.feature-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  font-size: 16px;
  padding: 20px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s;
}

.feature-item:hover {
  transform: translateY(-5px);
}

.feature-item i {
  font-size: 24px;
  color: #ff6b6b;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
  padding-bottom: 15px;
  border-bottom: 2px solid #f8f9fa;
}

.section-header h2 {
  font-size: 24px;
  color: #333;
}

.view-all {
  color: #666;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: color 0.3s;
}

.view-all:hover {
  color: #ff6b6b;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 30px;
  margin-bottom: 60px;
}

.advantages {
  padding: 60px 0;
  background: #f8f9fa;
}

.advantages-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 30px;
}

.advantage-item {
  text-align: center;
  padding: 30px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s;
}

.advantage-item:hover {
  transform: translateY(-5px);
}

.advantage-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 20px;
  background: #ff6b6b;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.advantage-icon i {
  font-size: 32px;
  color: white;
}

.advantage-item h3 {
  margin-bottom: 15px;
  color: #333;
}

.advantage-item p {
  color: #666;
  line-height: 1.6;
}

.featured-products,
.new-arrivals {
  padding: 40px 0;
}

@media (max-width: 1200px) {
  .product-grid,
  .advantages-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 992px) {
  .features .container {
    grid-template-columns: repeat(2, 1fr);
  }

  .product-grid,
  .advantages-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .product-grid,
  .advantages-grid {
    grid-template-columns: 1fr;
  }
}
</style> 